from tools_algorithm import *


class Solution:
    def unmarkedSumArray(self, nums: List[int], queries: List[List[int]]) -> List[int]:

        q = []
        for i, num in enumerate(nums):
            q.append((num, i))
        heapify(q)
        tot = sum(nums)
        ans = []
        for i, k in queries:
            tot -= nums[i]
            nums[i] = 0
            while k > 0 and q:
                num, j = heappop(q)
                tot -= nums[j]
                if nums[j] > 0:
                    nums[j] = 0
                    k -= 1
            ans.append(tot)
        return ans
